package com.rahms.server.controller;

import com.rahms.common.result.R;
import com.rahms.pojo.entity.Notification;
import com.rahms.server.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息通知控制器
 */
@RestController
@RequestMapping("/notification")
public class NotificationController {
    
    @Autowired
    private NotificationService notificationService;
    
    /**
     * 获取用户的消息列表
     */
    @GetMapping("/list")
    public R<List<Notification>> getNotificationsByUserId(@RequestParam Long userId,
                                                       @RequestParam(required = false) String type,
                                                       @RequestParam(required = false) Integer isRead) {
        List<Notification> list = notificationService.getNotificationsByUserId(userId, type, isRead);
        return R.success(list);
    }
    
    /**
     * 获取未读消息数量
     */
    @GetMapping("/unread-count")
    public R<Integer> getUnreadCountByUserId(@RequestParam Long userId) {
        int count = notificationService.getUnreadCountByUserId(userId);
        return R.success(count);
    }
    
    /**
     * 标记消息为已读
     */
    @PostMapping("/mark-read")
    public R<Boolean> markAsRead(@RequestParam Long notiId) {
        boolean result = notificationService.markAsRead(notiId);
        return result ? R.success(true) : R.error("标记失败");
    }
    
    /**
     * 批量标记消息为已读
     */
    @PostMapping("/batch-mark-read")
    public R<Boolean> batchMarkAsRead(@RequestBody List<Long> notiIds) {
        boolean result = notificationService.batchMarkAsRead(notiIds);
        return result ? R.success(true) : R.error("批量标记失败");
    }
}